<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">订单号</label>
                            <div class="layui-input-inline">
                                <input type="text" id="orderNum" name="orderNum" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">订单状态</label>
                            <div class="layui-input-inline">
                                <input type="text" id="orderStatus" name="orderStatus" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">订单创建人</label>
                            <div class="layui-input-inline">
                                <input type="text" id="creatUserName" name="creatUserName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">订单接单人</label>
                            <div class="layui-input-inline">
                                <input type="text" name="acceptUserName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="search"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">

        </script>

        <table class="layui-hide" id="orderTable" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="see">查看</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="update">完成订单</a>
        </script>

    </div>
</div>
<script th:src="@{/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script th:inline="javascript">
    var userName = [[${information.userInformationName}]];
</script>
<script th:inline="none">
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        var orderTable=table.render({
            elem: '#orderTable',
            url: '/order/queryReceive',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {type: 'numbers', title: '序号', width: 40},
                {field: 'orderNum', width: 120, title: '订单号'},
                {field: 'orderStartTime', width: 150, title: '订单创建日期'},
                {field: 'orderEndTime', width: 150, title: '订单结束日期'},
                {field: 'creatUserName', width: 150, title: '订单创建人'},
                {field: 'acceptUserName', width: 150, title: '订单接单人'},
                {
                    field: 'orderStatus', width: 120, align: 'center', title: '订单状态', templet: function (d) {
                        if (d.orderStatus == 'new') {
                            return '<input type="text" value="新建" autocomplete="off" class="layui-input" disabled="disabled">';
                        } else if (d.orderStatus == 'complete'){
                            return '<input type="text" value="完成" autocomplete="off" class="layui-input" disabled="disabled">';
                        } else if (d.orderStatus == 'accept'){
                            return '<input type="text" value="接单中" autocomplete="off" class="layui-input" disabled="disabled">';
                        } else if (d.orderStatus == 'cancel'){
                            return '<input type="text" value="已取消" autocomplete="off" class="layui-input" disabled="disabled">';
                        }
                        else if (d.orderStatus == 'update'){
                            return '<input type="text" value="修改" autocomplete="off" class="layui-input" disabled="disabled">';
                        }
                    }
                },
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });
        layui.laytpl('#indexTpl').render(function(index){
            return index + 1;
        });

        /// 监听搜索操作
        form.on('submit(search)', function (data) {
            var orderNum=$("#orderNum").val();
            var orderStatus=$("#orderStatus").val();
            var orderSettlementFlag=$("#orderSettlementFlag").val();
            var creatUserName=$("#creatUserName").val();
            var acceptUserName=$("#acceptUserName").val();
            //执行搜索重载
            table.reload('orderTable', {
                page: {
                    curr: 1
                }
                , where: {
                    orderNum: orderNum,
                    orderStatus: orderStatus,
                    orderSettlementFlag: orderSettlementFlag,
                    creatUserName: creatUserName,
                    acceptUserName: acceptUserName,
                }
            }, 'data');

            return false;
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var orderNum = data.orderNum;
            if (obj.event === 'see') {
                var index = layer.open({
                    title: '订单详情',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/order/orderDetail?orderNum='+ orderNum,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
            if (obj.event === 'update') {
                var creatUserName = data.creatUserName;

                $.ajax({
                    url: '/order/finish?orderNum='+orderNum,
                    type: "POST",
                    success: function (data) {
                        if (data.code == 200) {
                            layer.alert(data.message,{
                                title: "提示",
                            },function (index){
                                // 关闭弹出层
                                layer.close(index);
                                orderTable.reload();
                            })
                        }else{
                            layer.alert(data.message,{
                                title: "提示",
                            },function (index){
                                // 关闭弹出层
                                layer.close(index);
                                orderTable.reload();
                            })
                        }
                    }
                });

            }
        });

    });
</script>

</body>
</html>